package mathgame.gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import mathgame.ctrl.ControlFactory;


public class StartPanel extends GamePanel {

    private JButton jPracticeBtn, jTimeAttackBtn, jHighscoreBtn, jLearnBtn;

    public StartPanel(){

        this.setLayout(null);

        icon = createImageIcon("../source/StartPanel2.png", "background");
        jLearnBtn = new JButton();
        jLearnBtn.setFont(new Font("monospaced", Font.BOLD, 20));
        jLearnBtn.setText("EXAMPLES");
        jPracticeBtn = new JButton();
        jPracticeBtn.setFont(new Font("monospaced", Font.BOLD, 25));
        jPracticeBtn.setText("PRACTICE");
        jTimeAttackBtn = new JButton();
        jTimeAttackBtn.setFont(new Font("monospaced", Font.BOLD, 25));
        jTimeAttackBtn.setText("TIME ATTACK");
        jHighscoreBtn = new JButton();
        jHighscoreBtn.setFont(new Font("monospaced", Font.BOLD, 20));
        jHighscoreBtn.setText("HIGHSCORE");

        jTimeAttackBtn.addActionListener(actionListener);
        jPracticeBtn.addActionListener(actionListener);
        jHighscoreBtn.addActionListener(actionListener);
        jLearnBtn.addActionListener(actionListener);

        this.add(jTimeAttackBtn);
        this.add(jPracticeBtn);
        this.add(jExitBtn);
        this.add(jHelpBtn);
        this.add(jHighscoreBtn);
        this.add(jLearnBtn);

        Insets insets = this.getInsets();
        int WIDTH_LARGE = 280;
        int HEIGHT_LARGE = 100;
        int WIDTH_SMALL = 150;
        int HEIGHT_SMALL = 40;

        jPracticeBtn.setBounds(550 + insets.left, 180 + insets.top, WIDTH_LARGE, HEIGHT_LARGE);
        jTimeAttackBtn.setBounds(550 + insets.left, 320 + insets.top, WIDTH_LARGE, HEIGHT_LARGE);
        jExitBtn.setBounds(800 + insets.left, 520 + insets.top, WIDTH_SMALL, HEIGHT_SMALL);
        jHelpBtn.setBounds(620 + insets.left, 520 + insets.top, WIDTH_SMALL, HEIGHT_SMALL);
        jHighscoreBtn.setBounds(440 + insets.left, 520 + insets.top, WIDTH_SMALL, HEIGHT_SMALL);
        jLearnBtn.setBounds(260 + insets.left, 520 + insets.top, WIDTH_SMALL, HEIGHT_SMALL);

        this.setOpaque(false);
    }

    protected void paintComponent(Graphics g){
        g.drawImage(icon.getImage(), 0, 0, null);
        super.paintComponent(g);
    }


    ActionListener actionListener = new ActionListener(){
        public void actionPerformed(ActionEvent e){
            if(e.getSource() == jTimeAttackBtn){
                controller.changeCard(2);
            }
            else if(e.getSource() == jPracticeBtn){
                controller.changeCard(3);
            }
            else if(e.getSource() == jHighscoreBtn){
                controller.changeCard(4);
                controller.initiateHighscore();
            }
            else if(e.getSource() == jLearnBtn){
                controller.changeCard(5);
            }
        }
    };
}